package com.wanglemei.edm.service.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.wanglemei.edm.service.IEdmService;
import com.wanglemei.mail.service.ISendMailService;
import com.wanglemei.mail.util.EmailAuthenticator;
import com.wanglemei.mail.util.EmailServer;
import com.wanglemei.mail.util.SendMail;
import com.wanglemei.util.EmailUtils;

public class EdmServiceImpl implements IEdmService
{
	private ISendMailService iSendMailService;
	private final static String PASS_WORD="wanglemei123";
	private String mailSubject="这是一封测试邮件1" ;
	private String  mailContent="这是一封测试邮件2";

	@Override
	public void edm()
	{
		/** counter **/
		int counts=0;

		Set<String> toMailSet = new HashSet<String>();
		toMailSet.add("41054472@qq.com");
	   toMailSet.add("271323576@qq.com");
		
		
		List<String> mailSet126 = new ArrayList<String>();
		mailSet126.add("wanglemei1@126.com");
		mailSet126.add("wanglemei2@126.com");
		List<String> mailSet163 = new ArrayList<String>();
		mailSet163.add("wanglemei2@163.com");
		mailSet163.add("wanglemei3@163.com");
		
		
		/** sender **/
		List<String> fromMailList = new ArrayList<String>();
		/** receiver **/
		List<String> toMailList = new ArrayList<String>();

		toMailList.addAll(toMailSet);

	//	for (int i = 0; i < 100; i++)
	//	{
		//	for (int j = 0; j < mailSet126.size(); j++)
		//	{
				//fromMailList.addAll(mailSet126);
				fromMailList.addAll(mailSet163);
			//}
		//}
		/** start send mail **/
		for (int i = 0; i < fromMailList.size(); i++)
		{

			String to = toMailList.get(i);

			// validate Email Address
			if (EmailUtils.validateEmailAddress(to))
			{

				EmailServer emailServer = EmailServer.getEmailServerByAddress(EmailUtils.getMspByMail(fromMailList.get(i)));
				

			//	boolean flag = iSendMailService.sendMail(to, mailSubject, mailContent, emailServer, new EmailAuthenticator(fromMailList.get(i), PASS_WORD));
		//	boolean flag = SendMail.send(to, mailSubject, mailContent, emailServer, new EmailAuthenticator(fromMailList.get(i), PASS_WORD));
				SendMail sm=new SendMail(fromMailList.get(i), PASS_WORD);
				sm.send(to, mailSubject, mailContent, emailServer);

			
					counts++;
				
			}
			
			if (i==1)
			{
				break;
			}

		}
		
	        
		EmailServer emailServer = EmailServer.getEmailServerByAddress("126.com");
		
		SendMail sm=new SendMail("gy007123@126.com", PASS_WORD);
		sm.send("41054472@qq.com", "计数","----"+counts, emailServer);
		//	boolean flag = iSendMailService.sendMail(to, mailSubject, mailContent, emailServer, new EmailAuthenticator(fromMailList.get(i), PASS_WORD));
		//boolean flag = SendMail.send("41054472@qq.com", "计数","-----"+counts, emailServer, new EmailAuthenticator("gy007123@126.com","guoyang0903"));

	}

	public ISendMailService getiSendMailService()
	{
		return iSendMailService;
	}

	public void setiSendMailService(ISendMailService iSendMailService)
	{
		this.iSendMailService = iSendMailService;
	}

	
	
	public static void main(String[] args)
	{
		   new EdmServiceImpl().edm();
	}
}
